package com.example.gitport03;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.myapplication.R;

public class CarDetailActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_car_detail);

        ImageView carImg = findViewById(R.id.img_car_detail);
        TextView carName = findViewById(R.id.text_car_detail_name);
        TextView carBrief = findViewById(R.id.text_car_detail_brief);
        TextView priceAnalysis = findViewById(R.id.text_price_analysis);
        TextView usageInfo = findViewById(R.id.text_usage_info);

        Button btnshoucang=findViewById(R.id.btn_shoucang);
        Button btnjaruxihuan=findViewById(R.id.btn_jaruxihuan);
        Button btnxunwenjage=findViewById(R.id.btn_xunwenjage);


        carName.setText(getIntent().getStringExtra("carName"));
        carImg.setImageResource(getIntent().getIntExtra("carImg", R.drawable.wu));
        carBrief.setText(getIntent().getStringExtra("carBrief"));
        priceAnalysis.setText(getIntent().getStringExtra("priceAnalysis"));

        usageInfo.setText(getIntent().getStringExtra("usageInfo"));

        // 收藏点击事件
        btnshoucang.setOnClickListener(v -> {
            Toast.makeText(CarDetailActivity.this, "以添加收藏", Toast.LENGTH_SHORT).show();
            // 实际可写： 调用接口提交询价、弹窗输入信息等逻辑
        });

        // 询底价按钮点击事件
        btnxunwenjage.setOnClickListener(v -> {
            Toast.makeText(CarDetailActivity.this, "已提交询价", Toast.LENGTH_SHORT).show();
            // 实际可写： 调用接口提交询价、弹窗输入信息等逻辑
        });


        // 加入喜欢按钮点击事件（关键修正点）
        btnjaruxihuan.setOnClickListener(v -> {
            // 提取车名文本（从 TextView 中获取字符串）
            String selectedCarName = carName.getText().toString().trim();

            // 创建返回数据的 Intent
            Intent resultIntent = new Intent();
            resultIntent.putExtra("selectedCarName", selectedCarName); // 传递字符串

            // 设置结果码并关闭页面
            setResult(RESULT_OK, resultIntent);
            finish();

            Toast.makeText(CarDetailActivity.this, "返回成功", Toast.LENGTH_SHORT).show();
        });

    }
}